package com.ksyun.whgc.heruiming.work3;

public class MyThread extends Thread {

    public static String Flag = "";

    private String id;
    private String nextFlag;

    public MyThread(String id, String nextFlag) {
        this.id = id;
        this.nextFlag = nextFlag;
    }

    @Override
    public void run() {
        print(id,nextFlag);
    }

    public static synchronized void print(String id,String nextFlag) {
        try {
            for (int i = 0; i < 5; i++) {
                while(!Flag.equals(id)){
                    MyThread.class.wait();
                }
                System.out.print(id);
                Flag=nextFlag;
                MyThread.class.notifyAll();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
